#include <iostream>

using namespace std;
int a[30][30],n;

void dfs(int x, int y)
{
    if(x>=0&&x<=n+1&&y>=0&&y<=n+1)
    {
        if(a[x][y]==1||a[x][y]==3) return;
        else{
            a[x][y]=3;

             dfs(x,y+1 dfs(x,y-1););
             dfs(x-1,y);
             dfs(x+1,y);
        }
    }
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
            cin>>a[i][j];
    }
    dfs(0,0);
    for(int i=1;i<=n;i++)
    {
      for(int j=1;j<=n;j++)
        {
            if(a[i][j]==0) a[i][j]=2;
            if(a[i][j]==3) a[i][j]=0;
        }
    }

    for(int i=1;i<=n;i++)
    {
     for(int j=1;j<=n;j++)
        cout<<a[i][j]<<" ";
        cout<<endl;
    }
    return 0;
}
